#ifndef _SW_I2C_
#define _SW_I2C_

#include "stm32f1xx_hal.h"
#include "main.h"

#define SW_I2C1		        1

#define SW_I2C1_SCL_PORT    GPIOA
#define SW_I2C1_SDA_PORT    GPIOA
#define SW_I2C1_SCL_PIN     GPIO_PIN_10
#define SW_I2C1_SDA_PIN     GPIO_PIN_11

#define SW_I2C_WAIT_TIME    200
#define I2C_READ            0x01
#define READ_CMD            1
#define WRITE_CMD           0
#define SW_I2C_TRUE         1
#define SW_I2C_FALSE        0

void i2c_send_ack(uint8_t sel);
uint8_t i2c_check_ack(uint8_t sel);
void i2c_port_initial(uint8_t sel);
void i2c_start_condition(uint8_t sel);
void i2c_stop_condition(uint8_t sel);
void i2c_check_not_ack(uint8_t sel);
void i2c_register_address(uint8_t sel, uint8_t addr);
void TIMER__Wait_us(uint32_t nCount);
void i2c_slave_address(uint8_t sel, uint8_t IICID, uint8_t readwrite);
void Sw_I2c_Write_Data(uint8_t sel, uint8_t data);
uint8_t Sw_I2c_Read_Data(uint8_t sel);
uint8_t Sw_I2c_Read_8addr(uint8_t sel, uint8_t IICID, uint8_t regaddr, uint8_t *pdata, uint8_t rcnt);
uint8_t Sw_I2c_Read_16addr(uint8_t sel, uint8_t IICID, uint16_t regaddr, uint8_t *pdata, uint8_t rcnt);
uint8_t Sw_I2c_Write_8addr(uint8_t sel, uint8_t IICID, uint8_t regaddr, uint8_t *pdata, uint8_t rcnt);
uint8_t Sw_I2c_Write_16addr(uint8_t sel, uint8_t IICID, uint16_t regaddr, uint8_t *pdata, uint8_t rcnt);
uint8_t Sw_I2c_Check_SlaveAddr(uint8_t sel, uint8_t IICID);

#endif